package com.zhdl.hardware.clamping_jaw.inspire.repository.impl;

import com.project.command.faq.event.behavior.BehaviorPerform;
import com.zhdl.hardware.clamping_jaw.inspire.repository.InspirePortCmdHandleDao;
import com.zhdl.modules.tools.CommonCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Component
public class InspirePortCmdHandleDaoImpl implements InspirePortCmdHandleDao {
    @Resource
    public BehaviorPerform behaviorPerform;
    public Map<String, InspireCmdHandleDaoImpl> daoMap = new ConcurrentHashMap<>();

    /**
     * 添加串口
     *
     * @param port 串口号
     */
    @Override
    public void addPort(String port) {
        InspireCmdHandleDaoImpl inspireCmdHandleDao = new InspireCmdHandleDaoImpl(port, behaviorPerform);
        daoMap.put(port, inspireCmdHandleDao);
    }


    /**
     * 因时机器人-串口电机运动通用调试
     *
     * @param port 串口
     * @param cmd 指令
     * @param callback 回调
     */
    @Override
    public void inspireGenericCmd(String port, String cmd, CommonCallback<byte[]> callback){
        daoMap.get(port).inspireGenericCmd(cmd, callback);
    }

}
